//1.判断是否已经登录
//2.将公用的ajax提取出来
$(function () {
    let isLogin = sessionStorage.getItem("loginName");
    // console.log(isLogin)
    // console.log(typeof null)
    if (!isLogin) {
        // console.log("true")
        window.open("/html/login.html", "_self");
        // } else {
        //     console.log("false")
    }
});

function myAjax(url, data, type) {
    let result = null;
    $.ajax({
        url: url,
        data: data,
        type: type,
        async: false,
        dataType: 'json',
        success: function (data) {
            console.log(data);
            if (data.result == "notLogin") {
                layer.msg('当前用户未登录状态,请重新登录');
                window.open("/html/login.html", "_self");
            } else {
                result = data;
            }

        }
    });
    return result;
}


function myFileAjax(url, data, type) {
    let result = null;
    $.ajax({
        url: url,
        data: data,
        type: type,
        async: false,
        dataType: 'json',
        processData: false,
        contentType: false,
        success: function (data) {
            console.log(data);
            if (data.result == "notLogin") {
                layer.msg('当前用户未登录状态,请重新登录');
                window.open("/html/login.html", "_self");
            } else {
                result = data;
            }
        }
    });
    return result;
}